$(function () {
    getIndexMenu3(0, 0);

    function getIndexMenu1() {
        $.ajax({
            url: "http://139.199.157.195:9090/api/getgsshop",
            success: function (ext) {
                var html = template("CoudanList-top-1", ext);
                $(".popsort>ul").html(html);
                // var sty = html.find("#on");
                // console.log(ext);
                // if($('html>li>a').prop('name') == 0){
                //     $(".popsort>ul").html(html);
                // }else {
                //      $('html>li>a').removeClass('glyphicon glyphicon-ok');
                //       $(".popsort>ul").html(html);
                // }
                console.log(typeof html);
            }
        })
    }
    getIndexMenu1();
    function getIndexMenu2() {
        $.ajax({
            url: "http://139.199.157.195:9090/api/getgsshoparea",
            success: function (ext) {
                var html = template("CoudanList-top-2", ext);
                $(".popsbox>ul").html(html);
            }
        })
    }
    getIndexMenu2();

    var shid = 0;
    var areid = 0;

    $('.popsort>ul').on('click', "li", function () {
        $('.popsort>ul>li>span').removeClass('glyphicon glyphicon-ok');

        ($(this).find('span')).addClass('glyphicon glyphicon-ok');
        shid = ($(this).find('a')).prop('name');
        // console.log(shid);
        getIndexMenu3(shid, areid);
    });

    $('.popsbox>ul').on('click', "li", function () {
        $('.popsbox>ul>li>span').removeClass('glyphicon glyphicon-ok');
        ($(this).find('span')).addClass('glyphicon glyphicon-ok');
        areid = ($(this).find('a')).prop('name');
        console.log(areid);
        getIndexMenu3(shid, areid);
    });

    function getIndexMenu3(shid, areid) {
        $.ajax({
            url: "http://139.199.157.195:9090/api/getgsproduct?shopid=" + shid + "&areaid=" + areid,
            success: function (ext) {
                var html = template("CoudanList-top-3", ext);
                $(".section>ul").html(html);
                console.log($('.price').html().substring(1));

                var litre = [];
                var drop = [];
                $('#jiagesheng').on('click', function () {
                    var lis = $(".section>ul>li");
                    for (var i = 0; i < lis.length; i++) {
                        litre.push(($('.price').html().substring(1)));
                    }
                    drop = litre.sort(function (a, b) { return a - b; })
                    for (var j = 0; j < litre.length; j++) {

                        for (var p = 0; p < drop.length; p++) {

                            if (litre[j] == ($('.price').html().substring(1))) {
            
                                $('.section>ul').html(drop[p].html);
                                console.log(drop[p]);
                            }
                        }
                    }
                })

            }
        })
    }

    var flag = true;
    function rdisplay(prop, next, label, ext, not, adc, bac, set, cba) {
        $(prop).on('click', function () {
            if (flag == true) {
                $(next).css("display", "block");
                $(ext).css("display", "none");
                $(not).css("display", "none");
                $(set).css("display", "none");
                $(label).removeClass('glyphicon glyphicon-triangle-bottom');
                $(label).addClass('glyphicon glyphicon-triangle-top');
                $(adc).removeClass('glyphicon glyphicon-triangle-top');
                $(bac).removeClass('glyphicon glyphicon-triangle-top');
                $(cba).css('background-image', 'url("../images/sousuo.png")');
                $(adc).addClass('glyphicon glyphicon-triangle-bottom');
                $(bac).addClass('glyphicon glyphicon-triangle-bottom');
                flag = false;
            } else {
                $(next).css("display", "none");
                $(label).removeClass('glyphicon glyphicon-triangle-top');
                $(label).addClass('glyphicon glyphicon-triangle-bottom');
                flag = true;
            }
        })
    };
    rdisplay('#on', '.popsort', '#a', '.popsbox', '.popsbtn', '#b', '#c', '.popsset', '.search>i');
    rdisplay('#area', '.popsbox', '#b', '.popsort', '.popsbtn', '#a', '#c', '.popsset', '.search>i');
    rdisplay('#money', '.popsbtn', '#c', '.popsort', '.popsbox', '#a', '#b', '.popsset', '.search>i');

    $('.search').on('click', function () {
        if (flag == true) {
            $('.popsset').css("display", "block");
            $('.search>i').css('background-image', 'url("../images/sousuo1.png")');
            $('.popsort').css("display", "none");
            $('.popsbox').css("display", "none");
            $('.popsbtn').css("display", "none");
            $('#a').removeClass('glyphicon glyphicon-triangle-top');
            $('#b').removeClass('glyphicon glyphicon-triangle-top');
            $('#c').removeClass('glyphicon glyphicon-triangle-top');
            $('#a').addClass('glyphicon glyphicon-triangle-bottom');
            $('#b').addClass('glyphicon glyphicon-triangle-bottom');
            $('#c').addClass('glyphicon glyphicon-triangle-bottom');
            flag = false;
        } else {
            $('.popsset').css("display", "none");
            $('.search>i').css('background-image', 'url("../images/sousuo.png")');
            flag = true;
        }
    })

    $('.popsbtn>ul').on('click', "li", function () {
        $('.popsbtn>ul>li>span').removeClass('glyphicon glyphicon-ok');
        ($(this).find('span')).addClass('glyphicon glyphicon-ok');
    });

    $('.clocr>dd').on('click', "a", function () {
        $('.clocr>dd>a').removeClass('beset');
        $(this).addClass('beset');
    });

    $('.clorc>dd').on('click', "a", function () {
        $('.clorc>dd>a').removeClass('bset');
        $(this).addClass('bset');
    });


})




